package com.framework.main.sys.attachment.service; 

import java.io.File;
import java.util.List;

import com.framework.base.service.BaseServiceImp;
import com.framework.base.service.ServiceException;
import com.framework.base.util.FileUtil;
import com.framework.main.sys.attachment.dao.AttachmentDao;
import com.framework.main.sys.attachment.domain.AttachmentVo;

/**
 * Description:功能描述
 * tabaleName(对应的表名):
 * Company: www.51wuxia.com
 * @author：www.51wuxia.com
 * @version 1.0
 */
public class AttachmentServiceImp extends BaseServiceImp implements AttachmentService{
	private AttachmentDao attachmentDao;
	/**
	 * 根据条件查询的附件数据列表
	 * @param foreignId 外键编号
	 * @param userTypef 用途类型
	 * @return 
	 * @throws Exception 
	 */
	public List<AttachmentVo> toAttachmentListByforeignId(String foreignId,String userType)  {
		return getAttachmentDao().toAttachmentListByforeignId(foreignId,userType);
	}
	/**
	 * 删除指定附件数据
	 * @author lbx
	 * @createTime 2011-06-27
	 */
	public String doDeleteFile(String idf){
		try {
			String[] pks={idf};
			this.doDelete(pks);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
		return "true";
	}
	/**
	 * 根据外键查询有的附件列表
	 * @param foreignId 业务表的主键
	 * @param userTypef 附件的用途 同时也用于区分同一业务不同位置的附件
	 * @return
	 */
	public void doDeleteByForeignId(String foreignId,String userType){
		attachmentDao.doDeleteByForeignId(foreignId, userType);
	}
	
	/**
	 * 判断读取附件的路径是否存在
	 * @author lbx
	 * @createTime 2011-07-05
	 */
	public String isToReaderFile(String attachId) throws Exception{
		AttachmentVo attach=(AttachmentVo)this.getBaseDao().getById("toView", attachId);
		File file=new File(FileUtil.rootPath+"\\"+attach.getDiskFilePathf());
		getLogger().info("file path:"+file.getPath());
		if(!file.exists()){
			return "false";
		}else{
            return "true";			
		}
	}
	
	public AttachmentDao getAttachmentDao() {
		return attachmentDao;
	}
	public void setAttachmentDao(AttachmentDao attachmentDao) {
		this.attachmentDao = attachmentDao;
		this.setBaseDao(attachmentDao);
	}
}
